<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="informationForm" role="form" method="post" action="environmentControl/update">
    <input type="hidden" name="id" id="informationId" th:value="${entity.id}"/>
    <div class="form-group">
        <label for="areaId">所属片区编码:</label>
        <select type="text" class="form-control" name="areaId" id="areaId">

        </select>
    </div>
    <div class="form-group">
        <label for="areaName">所属具体楼栋:</label>
        <select type="text" class="form-control" name="areaName" id="areaName">

        </select>
    </div>
    <div class="form-group">
        <label for="controlName">负责人：:</label>
        <input class="form-control" name="controlName" id="controlName" placeholder="请输入相应的负责人" th:value="${entity.controlName}" />
    </div>
    <div class="form-group">
        <label for="createTime">排班时间：:</label>
        <input type="date" class="form-control" name="createTime" id="createTime" th:value="${entity.createTime}"/>
    </div>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        var fileState = [[${entity.areaName}]];
        $("#areaName", window.top.document).append("<option  selected=true value=" + fileState + ">" + fileState + "</option>")
        $.post("dict/getType", {type: "AREAID_TYPE"},
            function (r) {
                var fileType = [[${entity.areaId}]];
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for (var i = 0; i < r.data.length; i++) {
                    if (fileType == r.data[i].value) {
                        $("#areaId", window.top.document).append("<option selected=true  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    } else {
                        $("#areaId", window.top.document).append("<option  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }

                }
            })
        // 楼栋之间的联动 啧啧啧
        $("#areaId",window.top.document).click(function () {
            var areaId =  $("#areaId option:selected" , window.top.document).val()
            $.post("dict/getType", {type: areaId},
                function (r) {
                    $("#areaName",window.top.document).empty()
                    for (var i = 0; i < r.data.length; i++) {
                        $("#areaName", window.top.document).append("<option value=" + r.data[i].value + ">" + r.data[i].value + "</option>");
                    }
                });
        });
        $('#informationForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                areaId: {
                    validators: {
                        notEmpty: {
                            message: '所属片区不能为空'
                        }
                    }
                },
                controlName: {
                    validators: {
                        notEmpty: {
                            message: '负责人不能为空'
                        }
                    }
                },
                createTime: {
                    validators: {
                        notEmpty: {
                            message: '时间不能为空'
                        }
                    }
                },
                areaName: {
                    validators: {
                        notEmpty: {
                            message: '具体楼栋不能为空'
                        }
                    }
                }
            }
        });

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
            var bootstrapValidator = $("#informationForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.post($("#informationForm", window.top.document).attr('action'), $("#informationForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                    } else {
                        window.Ewin.alert({message: '修改数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>